//
//  ZHJNetWorkingStatus.m
//  NetWorking
//
//  Created by 红军张 on 2018/7/5.
//  Copyright © 2018年 红军张. All rights reserved.
//

#import "ZHJNetWorkingStatus.h"
#import "ZHJReachabilityManager.h"

@implementation ZHJNetWorkingStatus

#pragma mark 监听网络状态
+ (void)startMonitoring:(void(^)(BOOL isNet))netBlock {
    //1.创建网络监听管理者
    ZHJReachabilityManager *manager = [ZHJReachabilityManager sharedManager];
    
    //2.监听网络状态的改变
    [manager setReachabilityStatusChangeBlock:^(ZHJReachabilityStatus status) {
        switch (status) {
            case ZHJReachabilityStatusUnknown:
                ZHJLog([LogManager getClassForCoderName:self],@"网络状态 未知");
                netBlock(NO);
                break;
            case ZHJReachabilityStatusNotReachable:
                ZHJLog([LogManager getClassForCoderName:self],@"网络状态 没有网络");
                netBlock(NO);
                break;
            case ZHJReachabilityStatusReachableViaWWAN:
                ZHJLog([LogManager getClassForCoderName:self],@"网络状态 3G");
                netBlock(YES);
                break;
            case ZHJReachabilityStatusReachableViaWiFi:
                ZHJLog([LogManager getClassForCoderName:self],@"网络状态 WIFI");
                netBlock(YES);
                break;
                
            default:
                break;
        }
    }];
    
    //3.开始监听
    [manager startMonitoring];
}

+(void)stopMonitoring {
    ZHJLog([LogManager getClassForCoderName:self],@"停止网络状态监听");
    [[ZHJReachabilityManager sharedManager] stopMonitoring];
}

@end
